package com.information.manage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.information.manage.basic.common.result.Result;
import com.information.manage.model.entity.AnalysisFileDo;
import com.information.manage.model.query.AddAnalysisFileQuery;
import com.information.manage.model.query.AnalysisFileQuery;
import com.information.manage.model.query.AnalysisFileUpdateQuery;
import com.information.manage.model.vo.AllStatisticVO;
import com.information.manage.service.AnalysisFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sy
 * @since 2021-12-27
 */
@Api(tags = "文件分析结果")
@RestController
@RequestMapping("/analysis/file")
public class AnalysisFileController {

    @Resource
    private AnalysisFileService analysisFileService;

    @GetMapping("/query/page")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    public Result<Page<AnalysisFileDo>> queryPage(AnalysisFileQuery analysisFileQuery) {
        return analysisFileService.queryPage(analysisFileQuery);
    }

    @GetMapping("/getById")
    @ApiOperation(value = "根据id查询", notes = "根据id查询")
    public Result<AnalysisFileDo> getById(Long id){
        AnalysisFileDo byId = analysisFileService.getById(id);
        return Result.ok(byId);
    }

    @GetMapping("/getFileEnclosurePath")
    @ApiOperation(value = "获取附件地址", notes = "获取附件地址")
    public Result<List<String>> getFileEnclosurePath(Long id, @RequestParam(value = "type", required = false, defaultValue = "1") Integer type){
        return analysisFileService.getFileEnclosurePath(id, type);
    }

    @PostMapping("/add")
    @ApiOperation(value = "手动添加", notes = "手动添加")
    public Result<Long> add(HttpServletRequest request, @ModelAttribute AddAnalysisFileQuery addAnalysisFileQuery, @RequestParam("enclosure") List<MultipartFile> enclosures){
        return analysisFileService.add(addAnalysisFileQuery, request, enclosures);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除", notes = "删除")
    public Result<Boolean> delete(@RequestBody List<Long> analysisFileIds){
        return analysisFileService.delete(analysisFileIds);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "修改")
    public Result<Boolean> updateAf(HttpServletRequest request, @ModelAttribute AnalysisFileUpdateQuery analysisFileUpdateQuery
            , @RequestParam(value = "enclosure", required = false) List<MultipartFile> enclosures){
        return analysisFileService.updateAf(request, analysisFileUpdateQuery, enclosures);
    }

    @GetMapping("/all/statistic")
    @ApiOperation(value = "各分类总量统计", notes = "各分类总量统计")
    public Result<List<AllStatisticVO>> allStatistic(){
        return analysisFileService.allStatistic();
    }


}
